/**
 * Copyright 2010 Per-Erik Bergman (per-erik.bergman@jayway.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package se.jayway.opengl.tutorial.mesh;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * SimplePlane is a setup class for Mesh that creates a plane mesh.
 * 
 * @author Per-Erik Bergman (per-erik.bergman@jayway.com)
 * 
 */
public class SimplePlane extends Mesh {

    /**
     * Create a plane with a default with and height of 1 unit.
     */
    public SimplePlane() {
	int maxIndices = 0;
	// this.hasColor = true;
	// this.hasTexCoords = false;
	// this.vertexSize = (3 + (hasColor ? 4 : 0) + (hasTexCoords ? 2 : 0)) *
	// 4;
	// this.tmpBuffer = new int[6 * vertexSize / 4];
	//
	// ByteBuffer buffer = ByteBuffer.allocateDirect(6 * vertexSize);
	// buffer.order(ByteOrder.nativeOrder());
	// vertices = buffer.asIntBuffer();
	//
	// if (maxIndices > 0) {
	// buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
	// buffer.order(ByteOrder.nativeOrder());
	// indices = buffer.asShortBuffer();
	// } else {
	// indices = null;
	// }
	this.hasColor = true;
	this.hasTexCoords = false;
	this.hasNormals = false;

	this.vertexSize = (3 + (hasColor ? 4 : 0) + (hasTexCoords ? 2 : 0) + (hasNormals ? 3
		: 0)) * 4;
	this.tmpBuffer = new int[6 * vertexSize / 4];

	ByteBuffer buffer = ByteBuffer.allocateDirect(6 * vertexSize);
	buffer.order(ByteOrder.nativeOrder());
	vertices = buffer.asIntBuffer();

	if (maxIndices > 0) {
	    buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
	    buffer.order(ByteOrder.nativeOrder());
	    indices = buffer.asShortBuffer();
	} else {
	    indices = null;
	}

	// setIndices(indices);
	setVertices(new float[] { -0.5f, -0.5f, -3, 1, 0, 0, 1, 0.5f, -0.5f,
		-3, 1, 0, 0, 1, 0.0f, 0.5f, -3, 1, 0, 0, 1,

		0.0f, -0.5f, -5, 0, 1, 0, 1, 1.0f, -0.5f, -5, 0, 1, 0, 1, 0.5f,
		0.5f, -5, 0, 1, 0, 1 });
	// setTextureCoordinates(textureCoordinates);
    }

    /**
     * Create a plane.
     * 
     * @param width
     *            the width of the plane.
     * @param height
     *            the height of the plane.
     */
    public SimplePlane(float width, float height) {

    }
}
